/*
 * Project: SpringCloudDemo-BUS-RabbitMQ
 * 
 * File Created at 2017年2月13日
 * 
 * Copyright 2016 CMCC Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * ZYHY Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license.
 */
package com.lucky.consumer;

import java.util.Date;

import com.lucky.share.Message;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;

/**
 * @Type RabbitMQProcess.java
 * @Desc 
 * @author hadoop
 * @date 2017年2月13日 下午3:55:46
 * @version 
 */
@Component
//@EnableScheduling
public class Reciever {


    @Bean
    public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory);
        factory.setMessageConverter(new Jackson2JsonMessageConverter());
        return factory;
    }

    @Bean
    public Queue queue() {
        return new Queue("mqqueue");
    }

    @RabbitHandler
//    @RabbitListener(queues = "mqqueue" , containerFactory="rabbitListenerContainerFactory")
    @RabbitListener(queues = "mqqueue")
    public void process(@Payload Message foo) {
        System.out.println(new Date() + "==== :" + foo.getId() + " -> " + foo.getContent());
    }

    /*@RabbitHandler
    public void process(@Payload String foo) {
        System.out.println(new Date() + "==== :" + foo);
    }*/


}


/**
 * Revision history
 * -------------------------------------------------------------------------
 * 
 * Date Author Note
 * -------------------------------------------------------------------------
 * 2017年2月13日 hadoop creat
 */